import { fetchList, edit, status } from '@/services/user/UserInfo';
import { recharge } from '@/services/user/UserBalance';
import { message } from 'antd';

export default {
  namespace: 'PVipUser',

  state: {
    dataTable: {
      total: 0,
      list: [],
    },
  },

  effects: {

    * fetchList({ payload }, { call, put }) {
      const response = yield call(fetchList, payload);
      if (response.code === 0) {
        let { list } = response.data;
        list = list.map(d => {
          d.tagIds = d.userInfoTagLinkList.map(dd => dd.tagId);
          return d;
        });
        yield put({
          type: 'chgDataTable',
          payload: { ...response.data, list },
        });
      }
    },

    * edit({ payload, callback }, { call }) {
      const response = yield call(edit, payload);
      if (response.code === 0) {
        message.success('修改成功').then();
        callback && callback();
      }
    },

    * status({ payload, callback }, { call }) {
      const response = yield call(status, payload);
      if (response.code === 0) {
        message.success('修改状态成功').then();
        callback && callback();
      }
    },

    * recharge({ payload, callback }, { call }) {
      const response = yield call(recharge, payload);
      if (response.code === 0) {
        message.success('充值成功').then();
        callback && callback();
      }
    },


  },

  reducers: {
    chgDataTable(state, action) {
      return {
        ...state,
        dataTable: action.payload,
      };
    },
  },
};
